package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/6 14:36
 */
@RestController
//@CrossOrigin
@RequestMapping("/admin/product")
public class CategoryController {
   @Autowired
   private BaseCategory1Service category1Service;
    @Autowired
    private BaseCategory2Service category2Service;
    @Autowired
    private BaseCategory3Service category3Service;
    @Autowired
    private BaseAttrInfoService attrInfoService;
    /**
     * 获取一级分类
     * @return
     */
   @RequestMapping("/getCategory1")
   public Result<List<BaseCategory1>> getCategory1s(){
       System.out.println("请求进来了");
       List<BaseCategory1> list = category1Service.list();
       return Result.ok(list);
   }
    /**
     * 获取二级分类
     * @return
     */
   @RequestMapping("/getCategory2/{category1Id}")
   public Result getCategory2s(@PathVariable("category1Id") Long category1Id){
       List<BaseCategory2> list = category2Service.getCategory2by1Id(category1Id);
       return Result.ok(list);
   }

    /**
     * 获取三级分类
     * @return
     */
    @RequestMapping("/getCategory3/{category2Id}")
    public Result getCategory3s(@PathVariable("category2Id") Long category2Id){
        List<BaseCategory3> list = category3Service.getCategory3by2Id(category2Id);
        return Result.ok(list);
    }

}
